
/*
拉钩第一模块作业
refer:
日期格式化： https://www.runoob.com/java/java-date-time.html
Calendar使用： https://blog.csdn.net/qq_42681225/article/details/100663882
**/
import java.util.Calendar;
import java.util.Date;
import java.util.Random;
import java.util.ArrayList;

import java.util.Scanner;
import java.text.ParseException;
import java.text.SimpleDateFormat;

public class HomeWork {
    public static void main(String[] args) throws ParseException {
        // first();
        // second();
        // third();
        fourth();
        // fifth();1
    }

    public static void first() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Scanner sc = new Scanner(System.in);
        Calendar cal = Calendar.getInstance();
        System.out.println("请输入日期，格式为：xxxx-xx-xx");
        Date input_dt;
        try {
            input_dt = sdf.parse(sc.next());
            cal.setTime(input_dt);
            int total_data_nums = Integer.parseInt(String.format("%tj", input_dt));
            String str = String.format("日期是%s年中的第%s天", cal.get(Calendar.YEAR), total_data_nums);
            System.out.print(str);
        } catch (ParseException e) {
            e.printStackTrace();
        }

    }

    public static void second() {
        int i = 1;
        int j = 1;
        for (i = 1; i <= 1000; i++) {
            int sum = 0;
            for (j = 1; j <= i - 1; j++) {
                if (i % j == 0) {
                    sum += j;
                }
            }
            if (sum == j)
                System.out.println(sum);
        }
    }

    public static void third() {
        Random random = new Random();
        ArrayList<Integer> ball = new ArrayList<Integer>();
        System.out.print("红球号吗:\b");
        while (ball.size() < 6) {
            int red_num = random.nextInt(33) + 1; // nextInt(33)范围：0-32
            if (ball.contains(red_num) == Boolean.FALSE) {
                ball.add(red_num);
                System.out.print(red_num + "  ");
            }
        }
        System.out.println();
        System.out.print("蓝球号吗:");
        int blue_num = random.nextInt(16) + 1;
        System.out.println(blue_num);

    }

    public static void fourth() {
        int[] array = new int[5];
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < array.length; i++) {
            int input_num = sc.nextInt();
            array[i] = input_num;
            System.out.println("当前元素个数:" + i);
            if (i >= array.length * 0.8) {
                int[] temp_array = new int[(int) (array.length * 1.5)];
                System.arraycopy(array, 0, temp_array, 0, array.length); //最后的参数是数组总个数
                array = new int[(int) (array.length * 1.5)];
                System.arraycopy(temp_array, 0, array, 0, temp_array.length-1);
                System.out.println("数组自动扩容成功" + array.length);
            }
        }
    }

    public static void fifth() {
        char[] array = { ' ', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i] + " ");
            for (int j = 1; j < array.length; j++) {
                if (i > 0) {
                    System.out.print(" + ");
                } else {
                    System.out.print(" " + array[j] + " ");
                }
            }
            System.out.println();
        }
    }
}
